package state.fromCsdn;

import state.fromCsdn.impl.NormalState;

/**
 * 账户
 */
public class Account extends AccountState {

    private AccountState state;

    private String owner;

    private Double balance;

    public String getOwner() {
        return owner;
    }

    public void setOwner(String owner) {
        this.owner = owner;
    }

    public Double getBalance() {
        return balance;
    }

    public void setBalance(Double balance) {
        this.balance = balance;
    }

    public AccountState getState() {
        return state;
    }

    public void setState(AccountState state) {
        this.state = state;
    }

    public Account(String owner, Double init) {
        this.owner = owner;
        this.balance = init;
        this.state = new NormalState(this);
        System.out.println("用户[" + owner + "]开户，初始金额[" + init + "]");
        System.out.println("----------------------------------------------");
    }

    @Override
    public void deposit(Double amount) {
        System.out.println("用户[" + owner + "] 存款 [" + amount + "]");
        state.deposit(amount);
        state.stateCheck();
        System.out.println("用户[" + owner + "] 余额 [" + this.balance + "]");
        System.out.println("用户[" + owner + "] 状态 [" + this.state.getClass().getName() + "]");
        System.out.println("----------------------------------------------");
    }

    @Override
    public void withdraw(Double amount) {
        System.out.println("用户[" + owner + "] 取款 [" + amount + "]");
        state.withdraw(amount);
        state.stateCheck();
        System.out.println("用户[" + owner + "] 余额 [" + this.balance + "]");
        System.out.println("用户[" + owner + "] 状态 [" + this.state.getClass().getName() + "]");
        System.out.println("----------------------------------------------");
    }

    @Override
    public void computeInterest() {
        state.computeInterest();
    }

    @Override
    public void stateCheck() {
        state.stateCheck();
    }
}
